package com.test.io;

import java.awt.List;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.LinkedList;


public class Exercise7 {
	public static void main(String[] args) throws IOException {
		System.out.println(read("G:/textTest.txt"));

	}
	/**
	 * read file by lines and return string in reverse order
	 * @param filePath
	 * @return
	 * @throws IOException
	 */
	public static String read(String filePath) throws IOException {
		LinkedList<String> fileLines = new LinkedList<String>();
		StringBuilder sBuilder = new StringBuilder();
		String s;
		BufferedReader read = new BufferedReader(new FileReader(filePath));
		while ((s = read.readLine()) != null) {
			fileLines.offer(s.toUpperCase());
		}
		while (!fileLines.isEmpty()) {
			sBuilder.append(fileLines.pollLast() + "\n");
		}
		return sBuilder.toString();
	}
}
